function out = fsb_avg(in,dim)

% FSB: calculates the average of a matrix over any dimension
%
% EXAMPLE:
% out = avg(in);
%
% INPUT:
% in: a matrix of any size
% dim: dimension over which mean is to be calculated
%
% OUTPUT:
% the mean value of the matrix
%
% CALLED BY:
% fsb_correct_intensity.m
% fsb_diag.m
% fsb_det_artifact_mod.m
%
% NOTES:
% will also accept nan values
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
% 
% $ Revision 1.0
%
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if nargin<2
    out = sum(in(:))/length(in(:));
else
    out = nanmean(in,dim);
end

end

